package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.domain.TravelCommend;
import cn.wolfcode.trip.base.query.TravelCommendQuery;
import cn.wolfcode.trip.base.service.ITravelCommendService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
@RequestMapping("/travelCommend")
public class TravelCommendController {
    @Autowired
    private ITravelCommendService travelCommendService;

    /**
     * 查看所有推荐游记
     * @param qo 条件/每周推荐/每月/攻略/分页
     * @return
     */
    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") TravelCommendQuery qo, Model model){
        qo.setOrderBy("com.schedule");
        PageInfo<TravelCommend> pageInfo = travelCommendService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "travelCommend/list";
    }

    /**
     * 保存或更新推荐文章
     * @param commend 推荐信息
     * @return
     */
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(TravelCommend commend, MultipartFile file){
        travelCommendService.saveOrUpdate(commend,file);
        return new JSONResult();
    }
}
